package com.ruoyi.project.jiaqin.quoted.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.quoted.domain.QuotedPrice;
import com.ruoyi.project.jiaqin.quoted.service.IQuotedPriceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 采购报价Controller
 * 
 * @author admin
 * @date 2020-12-25
 */
@Controller
@RequestMapping("/jiaqin/quoted")
public class QuotedPriceController extends BaseController
{
    private String prefix = "jiaqin/quoted";

    @Autowired
    private IQuotedPriceService quotedPriceService;

    @RequiresPermissions("jiaqin:quoted:view")
    @GetMapping()
    public String quoted()
    {
        return prefix + "/quoted";
    }

    /**
     * 查询采购报价列表
     */
    @RequiresPermissions("jiaqin:quoted:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuotedPrice quotedPrice)
    {
        startPage();
        List<QuotedPrice> list = quotedPriceService.selectQuotedPriceList(quotedPrice);
        return getDataTable(list);
    }

    /**
     * 导出采购报价列表
     */
    @RequiresPermissions("jiaqin:quoted:export")
    @Log(title = "采购报价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuotedPrice quotedPrice)
    {
        List<QuotedPrice> list = quotedPriceService.selectQuotedPriceList(quotedPrice);
        ExcelUtil<QuotedPrice> util = new ExcelUtil<QuotedPrice>(QuotedPrice.class);
        return util.exportExcel(list, "quoted");
    }

    /**
     * 新增采购报价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购报价
     */
    @RequiresPermissions("jiaqin:quoted:add")
    @Log(title = "采购报价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuotedPrice quotedPrice)
    {
        return toAjax(quotedPriceService.insertQuotedPrice(quotedPrice));
    }

    /**
     * 修改采购报价
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        QuotedPrice quotedPrice = quotedPriceService.selectQuotedPriceById(id);
        mmap.put("quotedPrice", quotedPrice);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购报价
     */
    @RequiresPermissions("jiaqin:quoted:edit")
    @Log(title = "采购报价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuotedPrice quotedPrice)
    {
        return toAjax(quotedPriceService.updateQuotedPrice(quotedPrice));
    }

    /**
     * 删除采购报价
     */
    @RequiresPermissions("jiaqin:quoted:remove")
    @Log(title = "采购报价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(quotedPriceService.deleteQuotedPriceByIds(ids));
    }
}
